/**
 * 对象预处理，类似java中的AOP
 */
let obj = {
    title: 'ES6',
    desc: 'ES6基础语法',
    add(a, b) {
        return a + b;
    }
}

let proxy = new Proxy(obj, {
    get(target, key) {
        console.log('get预处理...')
        console.log('target: ', target)
        console.log('key: ', key)
        return target[key]
    },
    set(target, key, value, receiver) {
        console.log(`设置target[${key}]=${value}，原始参数：${receiver}`)
        target[key] = value;
    }
})

console.log(proxy.title)
proxy.desc = 'ES611基础语法！！！'
console.log(proxy.desc)
console.log(proxy.add(1, 2))

/**
 * 函数预处理，类似java中的AOP
 */
let target = function(a, b) {
    console.log('This is a Target.')
    return a + b;
}
let handler = {
    apply(target, ctx, args) {
        console.log('func proxy=>', target);
        console.log('func proxy=>', ctx);
        console.log('func proxy=>', args);
        return Reflect.apply(...arguments)
    }
}
let funcProxy = new Proxy(target, handler);
console.log(funcProxy(2, 5));